package com.sptechsys.m2ejb32weblogic.ejb3.demo.ws;

import javax.jws.WebService;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.sptechsys.m2ejb32weblogic.ejb3.stateless.HelloWorld;

/**
 * 
 * Class HelloWorldServiceImpl<br>
 * 
 * @author <a href="mailto:info[at]sptechsys.com">SPTECHSYS</a>
 * @version 1.0
 */
@WebService(name = "HelloWorldPortType", serviceName = "HelloWorldService")
public class HelloWorldServiceImpl {
	
	private HelloWorld helloWorld;
	
	public String sayHelloWorld(String message) {
		try {
			System.out.println("sayHelloWorld:" + message);
		} catch (Exception ex) {
			ex.printStackTrace();			
		}
		return "Here is the message: '" + message + "'";
	}
	
	public String sayHelloToEjb(String message){
		Context ctx;
		try {
			ctx = new InitialContext();
		System.out.println("Initial Context created");
		helloWorld = (HelloWorld) ctx.lookup("HelloWorld#com.sptechsys.m2ejb32weblogic.ejb3.stateless.HelloWorld");
		System.out.println("Remote interface created");
		return helloWorld.sayHello(message);
		} catch (NamingException e) {
			e.printStackTrace();
			return null;
		}
	}

}
